package com.haiqi.common;

import com.haiqi.modules.main.bean.MenuResponse;
import com.haiqi.modules.main.bean.ResponseBean;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;
import java.lang.annotation.Annotation;
import java.util.List;

/**
 * Created by hythzx on 2016/5/12.
 */
public class BaseController implements Controller {

    public void generateMenuCode(HttpSession session,String menuCode){
        List<MenuResponse.MenusBean> menusList = (List<MenuResponse.MenusBean>) session.getAttribute("menu");
        MenuResponse.MenusBean currentMenu = new MenuResponse.MenusBean();
        MenuResponse.MenusBean parentMenu = new MenuResponse.MenusBean();
        for (MenuResponse.MenusBean menusBean : menusList) {
            menusBean.setMenuActive("");
            if(menusBean.getEname().equals(menuCode)){
                menusBean.setMenuActive("active");
                currentMenu = menusBean;
            }
        }

        for (MenuResponse.MenusBean menusBean : menusList) {
            if(menusBean.getId().equals(currentMenu.getParentid())){
                menusBean.setMenuActive("active");
                parentMenu = menusBean;
            }
        }

        session.setAttribute("parentMenu",parentMenu);
        session.setAttribute("currentMenu",currentMenu);
    }

    public ResponseBean.UserBean getUser(HttpSession session){
        ResponseBean.UserBean user = (ResponseBean.UserBean) session.getAttribute("user");
        return user;
    }

    @Override
    public String value() {
        return null;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return null;
    }
}
